import qs from 'qs'
import {
	setStore
} from '@/util/store';
import {
	encryption
} from '@/util/util';
import {
	btoa
} from 'js-base64'

export const loginByUsername = (data) => {
	const basicAuth = 'Basic ' + btoa('ayy:ayy');
	data.grant_type = 'password';
	data.scope = 'server';
	setStore({
		name: 'basicAuth',
		content: basicAuth
	})
	let encPassword = data.password;
	encPassword = encryption(data.password, 'thanks,pig4cloud');
	uni.$u.http.post('/auth/oauth2/token', {
		...data,
		password: encPassword
	}, {
		params: {},
		headers: {
			skipToken: true,
			Authorization: basicAuth,
			'Content-Type': 'application/x-www-form-urlencoded',
		},
	}).then(res => {
		console.log(res);
	}).catch(err => {
		console.log(err);
	})
}